from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
from django.conf import settings

s = Serializer(settings.SECRET_KEY, 300)

def code_signed_openid(openid):
    signed_openid = s.dumps({"openid":openid})
    return signed_openid.decode()


def decode_signed_openid(signed_openid):
    try:
        openid = s.loads(signed_openid)
    except Exception as e:
        return None
    return openid['openid']